<template>
  <div class="admin-home">
    <AppNavbar title="管理员首页" role="admin" />
    
    <div class="welcome-section">
      <h1 class="welcome-title">欢迎回来，{{ username }} 管理员</h1>
      <p class="welcome-subtitle">在这里管理系统的各项功能</p>
    </div>
    
    <el-card class="admin-functions">
      <template #header>
        <div class="card-header">
          <span>管理功能</span>
        </div>
      </template>
      <el-row :gutter="20" justify="center">
        <el-col :span="12">
          <div class="function-card" @click="goToUserManagement">
            <div class="function-icon">
              <i class="el-icon-user"></i>
            </div>
            <div class="function-content">
              <h3 class="function-title">用户管理</h3>
              <p class="function-desc">管理系统中的所有用户</p>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import AppNavbar from '@/components/AppNavbar.vue'

export default {
  name: 'AdminIndex',
  components: {
    AppNavbar
  },
  data() {
    return {
      username: ''
    }
  },
  created() {
    // 从localStorage获取用户信息
    const userInfo = localStorage.getItem('userInfo')
    if (userInfo) {
      try {
        const user = JSON.parse(userInfo)
        this.username = user.username
      } catch (e) {
        console.error('解析用户信息失败:', e)
      }
    }
  },
  methods: {
    goToUserManagement() {
      this.$router.push('/admin/users')
    }
  }
}
</script>

<style scoped>
.admin-home {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 40px);
}

.welcome-section {
  text-align: center;
  padding: 30px 0;
  margin-bottom: 30px;
}

.welcome-title {
  color: #303133;
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 10px;
}

.welcome-subtitle {
  color: #606266;
  font-size: 1.1rem;
}

.admin-functions {
  max-width: 800px;
  margin: 0 auto;
  border-radius: 10px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.card-header {
  font-size: 1.3rem;
  font-weight: 600;
  color: #303133;
}

.function-card {
  display: flex;
  align-items: center;
  padding: 20px;
  background: #ffffff;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #ebeef5;
}

.function-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.1);
  border-color: #409eff;
}

.function-icon {
  width: 50px;
  height: 50px;
  background: #ecf5ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  color: #409eff;
  font-size: 24px;
}

.function-content {
  flex: 1;
}

.function-title {
  margin: 0 0 5px 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: #303133;
}

.function-desc {
  margin: 0;
  font-size: 0.9rem;
  color: #909399;
}
</style>